package br.com.kapa.utils;

import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

public class Logs {

	@Resource(mappedName = "jms/FabricaIndustriaResource")
	public ConnectionFactory connectionFactory;

	@Resource(mappedName = "jms/IndustriaResource")
	public Queue queue;
	
	public void sendMessageToLog(String assunto, String valor) {

		try {
			Connection con = connectionFactory.createConnection();
			Session session = con
					.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer mp = session.createProducer(queue);

			TextMessage message = session.createTextMessage();
			message.setText(assunto + " : " + valor);
			mp.send(message);
			mp.close();
			session.close();
			con.close();
			System.out.println("enviado");

		} catch (NullPointerException npe) {
			npe.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
